<%@ page language="java"  pageEncoding="UTF-8"%>
<%@ include file="/views/commons/taglibs.jsp" %>
<input type="hidden" id="discuss_type"  name="discussType" value="${discussType}"/>
<input type="hidden" id="discuss_target_id"  name="discussTargetId" value="${discussTargetId}"/>
<div class="o-single-content__body__content">
	<div class="c-article-comments " id="article-comments">
		<h5 class="c-card-category c-article-comments__headline">
			文章评论
		</h5>
		<c:choose>
			<c:when test="${sessionUserInfo!=null && sessionUserInfo.userId !=null}">
				<div class="c-article-comments-item is-unauthenticated js-article-comments-post-field">
					<img alt="" src="" class="c-article-comments-item__avatar js-user-avatar">
					<div class="c-article-comments-item__info">
						<span style="display: none" class="js-article-comment-form-locator"></span>
						<form class="c-article-comments-form is-unauthenticated " action="javascript:insertDiscuss()" id="discuss_form">
							<div class="c-article-comments-form__textarea ">
								<textarea placeholder="你有什么看法呢" class="c-article-comments-form__input c-article-comments-form__input--textarea" id="discuss_info" name="discussInfo"></textarea>
							</div>
							<button class="btn btn-primary pull-right" type="submit" id="discuss_send_btn">发表评论</button>
						</form>
					</div>
				</div>
			</c:when>
			<c:otherwise>
				<div class="c-article-comments-item is-unauthenticated js-article-comments-post-field">
					<div class="c-article-comments-item__info">
					请登录后发表评论<a href="<%=path%>/uncheck/login" class="login">登录</a>
					</div>
				</div>
			</c:otherwise>
		</c:choose>
		<div id="discuss_list_div"></div>
	</div>
</div>
<script src="<%=path%>/js/plugins/layer/layer.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	queryDiscussList(1);
});

function queryDiscussList(pageNo){
	$.ajax({
		url : path + "/uncheck/discuss/list",
		type : "get",
		dataType : "html",
		data : {
			discussType : $("#discuss_type").val(),
			discussTargetId : $("#discuss_target_id").val(),
			pageNo:pageNo
		},
		success : function(data)
		{
			$("#discuss_list_div").html(data);
		},error:function(){
			layer.msg("服务器网络繁忙",{icon: 2});
		}
	});
}

function queryScoreList(discussScore){
	$("#discuss_score").val(discussScore);
	queryDiscussList(1);
}

function insertDiscuss(){
	$("#discuss_send_btn").addClass("disabled").attr("disabled","disabled").val("发送中");
	
	var insertData=$("#discuss_form").serialize();
	insertData=insertData+"&discussType="+$("#discuss_type").val()+"&discussTargetId="+ $("#discuss_target_id").val();
	$.ajax({
		url : path + "/check/discuss/insert",
		type : "post",
		dataType : "json",
		data : insertData,
		success : function(data)
		{
			if(data.result){
				
				$("#discuss_info").val("");
				layer.msg("发布评论成功",{icon: 1});
				
				$("#discuss_score").val("");
				
				queryDiscussList(1);
				
				$("#discuss_send_btn").removeClass("disabled").removeAttr("disabled").val("发送消息");
			}else{
				layer.msg(data.message,{icon: 2});
				$("#discuss_send_btn").removeClass("disabled").removeAttr("disabled").val("发送消息");
			}
		},error:function(){
			layer.msg("服务器网络繁忙",{icon: 2});
			$("#discuss_send_btn").removeClass("disabled").removeAttr("disabled").val("发送消息");
		}
	});
}
</script>
